<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>AngularJS基于模块化的MVC</title>
		<script type="text/javascript" src="../js/angular.min.js"></script>
	</head>

	<body ng-app="myApp" ng-controller="myController">
		<button class="btn btn-default" ng-click="getCheckCode()" ng-bind="btnMsg"></button>

	</body>

</html>
<script>
	var myApp = angular.module("myApp", []);
	myApp.controller("myController", ["$scope", function($scope) {
		$scope.btnMsg = "获取验证码";
		var active = true;
		var second = 60;
		var secondInterval;
		$scope.getCheckCode = function() {
						if(active==false){
							return;
						}
						active=false;
						secondInterval=setInterval(function(){
							if(second<0){
			//					//可以重发
								$scope.btnMsg="重发验证码";
								$scope.$digest();
								active=true;
								second=60;
								clearInterval(secondInterval);
								secondInterval=undefined;
							}else{
								$scope.btnMsg=second+"秒后重发";
								$scope.$digest();
								second--;
							}
						},1000);
		}

	}])
</script>